package com.yanqu.road.server.agent.inter;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.enums.eAgentErrorCode;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.agent.AgentInterfaceMgr;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.server.manger.player.GameChatControlMgr;

public class AgentReload {

	public String reloadMgr(JSONObject param) {
		JSONObject ret = AgentInterfaceMgr.getDefaultRet();
		String content = param.getString("content");
		try {
			for (TempMgr mgr : GameServer.getInstance().getMgrList()) {
				if (mgr.getClass().getSimpleName().equals(content)) {
					mgr.reload();
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		AgentInterfaceMgr.setCommonRet(ret, eAgentErrorCode.Success.getValue());
		return ret.toString();
	}

	public String reloadCrossOreWarPit(JSONObject param) {
		JSONObject ret = AgentInterfaceMgr.getDefaultRet();
		try {
			OreWarMgr.reloadCrossPit();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		AgentInterfaceMgr.setCommonRet(ret, eAgentErrorCode.Success.getValue());
		return ret.toString();
	}

	/**
	* 描述：重载mgr配置
	* 作者：zrq
	* 时间：2022/1/25
	* 参数：
	mgr名
	* 返回值：时候执行成功
	**/
	public String reloadMgrConfig(JSONObject param) {
		JSONObject ret = AgentInterfaceMgr.getDefaultRet();
		String content = param.getString("content");
		try {
			for (TempMgr mgr : GameServer.getInstance().getMgrList()) {
				if (mgr.getClass().getSimpleName().equals(content)) {
					mgr.reloadConfig();
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		AgentInterfaceMgr.setCommonRet(ret, eAgentErrorCode.Success.getValue());
		return ret.toString();
	}

	public String getUserChat(JSONObject param){
		return GameChatControlMgr.getUserChatMessage(param);
	}
}
